﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using YArchitech.Controls;
using YArchitech.LIB;
using HYRevitCode.FormUtility;

namespace QuickModel.Forms
{
	public partial class QuickModelSetupForm : System.Windows.Forms.Form
	{
		public int MinWallLength
		{
			get
			{
				return this.m_nMinWallLength;
			}
		}

		public int MinWallWidth
		{
			get
			{
				return this.m_nMinWallWidth;
			}
		}

		public int MaxWallWidth
		{
			get
			{
				return this.m_nMaxWallWidth;
			}
		}

		public QuickModelSetupForm()
		{
			this.InitializeComponent();
			this.hyTextBoxMinWallLength.IsInt = NumberType.integer;
			this.hyTextBoxMinWallWidth.IsInt = NumberType.integer;
			this.hyTextBoxMaxWallWidth.IsInt = NumberType.integer;
			this.m_thisFormManger = new ControlInfoManager(this, new List<KeyValuePair<System.Windows.Forms.Control, bool>>
			{
				new KeyValuePair<System.Windows.Forms.Control, bool>(this.hyTextBoxMinWallLength, false),
				new KeyValuePair<System.Windows.Forms.Control, bool>(this.hyTextBoxMinWallWidth, false),
				new KeyValuePair<System.Windows.Forms.Control, bool>(this.hyTextBoxMaxWallWidth, false)
			}, null, null);
			this.LoadDlgData();
		}

		public void LoadDlgData()
		{
			bool flag = !this.m_thisFormManger.SetControlInfoToForm();
			if (flag)
			{
				this.hyTextBoxMinWallLength.Text = "100";
				this.hyTextBoxMinWallWidth.Text = "100";
				this.hyTextBoxMaxWallWidth.Text = "300";
			}
			this.m_nMinWallLength = int.Parse(this.hyTextBoxMinWallLength.Text);
			this.m_nMinWallWidth = int.Parse(this.hyTextBoxMinWallWidth.Text);
			this.m_nMaxWallWidth = int.Parse(this.hyTextBoxMaxWallWidth.Text);
		}

		private bool GetDlgData()
		{
			TabPage selectedTab = this.tabQuickModelSetup.SelectedTab;
			this.tabQuickModelSetup.SelectedTab = this.tabWallSetPage;
			bool flag = !this.GetWallPageData();
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				this.tabQuickModelSetup.SelectedTab = selectedTab;
				result = true;
			}
			return result;
		}

		private bool GetAxisPageData()
		{
			return true;
		}

		private bool GetWallPageData()
		{
			bool flag = !this.GetPositiveInt(this.hyTextBoxMinWallLength, ref this.m_nMinWallLength);
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				bool flag2 = !this.GetPositiveInt(this.hyTextBoxMinWallWidth, ref this.m_nMinWallWidth);
				if (flag2)
				{
					result = false;
				}
				else
				{
					bool flag3 = !this.GetPositiveInt(this.hyTextBoxMaxWallWidth, ref this.m_nMaxWallWidth);
					if (flag3)
					{
						result = false;
					}
					else
					{
						bool flag4 = this.m_nMaxWallWidth <= this.m_nMinWallWidth;
						if (flag4)
						{
							YJKMessageBox.Show("墙最大宽度必须大于墙最小宽度！", MessageBoxButtons.OK, MessageBoxIcon.Hand);
							this.hyTextBoxMaxWallWidth.SelectAll();
							this.hyTextBoxMaxWallWidth.Focus();
							result = false;
						}
						else
						{
							result = true;
						}
					}
				}
			}
			return result;
		}

		private bool GetColumnPageData()
		{
			return true;
		}

		private bool GetPositiveInt(YJKTextBox inputBox, ref int nResult)
		{
			try
			{
				int num = int.Parse(inputBox.Text);
				bool flag = num <= 0;
				if (flag)
				{
					YJKMessageBox.Show("请输入大于0的整数！", MessageBoxButtons.OK, MessageBoxIcon.Hand);
					return false;
				}
				nResult = num;
			}
			catch
			{
				YJKMessageBox.Show("请输入大于0的整数！", MessageBoxButtons.OK, MessageBoxIcon.Hand);
				return false;
			}
			return true;
		}

		private void QuickModelSetupForm_Load(object sender, EventArgs e)
		{
			base.Icon = Resource.YArchitechIcon;
		}

		private void btnOk_Click(object sender, EventArgs e)
		{
			bool flag = !this.GetDlgData();
			if (!flag)
			{
				this.m_thisFormManger.GetControlInfoToXml();
				base.DialogResult = DialogResult.OK;
			}
		}

		private void QuickModelSetupForm_KeyDown(object sender, KeyEventArgs e)
		{
			bool flag = e.KeyCode == Keys.Escape;
			if (flag)
			{
				base.Close();
			}
		}

		private void hyTextBoxMinWallLength_Validating(object sender, CancelEventArgs e)
		{
			bool flag = !this.GetPositiveInt(this.hyTextBoxMinWallLength, ref this.m_nMinWallLength);
			if (flag)
			{
				this.hyTextBoxMinWallLength.Text = this.m_nMinWallLength.ToString();
				this.hyTextBoxMinWallLength.SelectAll();
				e.Cancel = true;
			}
		}

		private void hyTextBoxMinWallWidth_Validating(object sender, CancelEventArgs e)
		{
			bool flag = !this.GetPositiveInt(this.hyTextBoxMinWallWidth, ref this.m_nMinWallWidth);
			if (flag)
			{
				this.hyTextBoxMinWallWidth.Text = this.m_nMinWallWidth.ToString();
				this.hyTextBoxMinWallWidth.SelectAll();
				e.Cancel = true;
			}
			bool flag2 = this.m_nMaxWallWidth <= this.m_nMinWallWidth;
			if (flag2)
			{
				YJKMessageBox.Show("墙最大宽度必须大于墙最小宽度！", MessageBoxButtons.OK, MessageBoxIcon.Hand);
				this.hyTextBoxMinWallWidth.SelectAll();
				e.Cancel = true;
			}
		}

		private void hyTextBoxMaxWallWidth_Validating(object sender, CancelEventArgs e)
		{
			bool flag = !this.GetPositiveInt(this.hyTextBoxMaxWallWidth, ref this.m_nMaxWallWidth);
			if (flag)
			{
				this.hyTextBoxMaxWallWidth.Text = this.m_nMaxWallWidth.ToString();
				this.hyTextBoxMaxWallWidth.SelectAll();
				e.Cancel = true;
			}
			bool flag2 = this.m_nMaxWallWidth <= this.m_nMinWallWidth;
			if (flag2)
			{
				YJKMessageBox.Show("墙最大宽度必须大于墙最小宽度！", MessageBoxButtons.OK, MessageBoxIcon.Hand);
				this.hyTextBoxMaxWallWidth.SelectAll();
				e.Cancel = true;
			}
		}

		private ControlInfoManager m_thisFormManger = null;

		private int m_nMinWallLength;

		private int m_nMinWallWidth;

		private int m_nMaxWallWidth;
	}
}
